﻿
Partial Public Class OptionsWindow

    Private Pages As New List(Of Page)

    Private Sub ContentFrame_Navigated(ByVal sender As Object, ByVal e As System.Windows.Navigation.NavigationEventArgs) Handles ContentFrame.Navigated

        Dim page = DirectCast(DirectCast(sender, Frame).Content, Page)

        If TypeOf page Is PluginPage Then
            page.DataContext = DirectCast(Me.DataContext, ViewModel.MainWindowViewModel).PluginsViewSource
        Else
            page.DataContext = DirectCast(Me.DataContext, ViewModel.MainWindowViewModel).UISettings
        End If

        If Not Pages.Contains(page) Then
            Pages.Add(page)
            page.BindingGroup.BeginEdit()
        End If
    End Sub

    Private Sub OkButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)

        For Each p In Pages
            p.BindingGroup.CommitEdit()
        Next
        Me.DialogResult = True
        Me.Close()
    End Sub

    Private Sub Cansel_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        For Each p In Pages
            p.BindingGroup.CancelEdit()
        Next
        Me.DialogResult = False
        Me.Close()
    End Sub

    Private Sub OptionsWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        Me.MoveToCenter()
    End Sub
End Class

